package com.ctgu.computer.service.impl;

import com.ctgu.computer.domain.dto.CheckDTO;
import com.ctgu.computer.domain.dto.CheckReportDTO;
import com.ctgu.computer.domain.dto.PageQueryDTO;
import com.ctgu.computer.domain.po.ReportInfo;
import com.ctgu.computer.domain.result.PageResult;
import com.ctgu.computer.mapper.CheckMapper;
import com.ctgu.computer.service.CheckService;
import com.ctgu.computer.service.ReportService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.RequiredArgsConstructor;
import org.dromara.x.file.storage.core.exception.Check;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class CheckServiceImpl implements CheckService {
    @Autowired
    private CheckMapper checkMapper;
    @Override
    public PageResult getAllUserReport(PageQueryDTO pageQueryDTO) {
        PageHelper.startPage(pageQueryDTO.getPageIndex(),pageQueryDTO.getPageSize());

        Page<ReportInfo> result = checkMapper.list();

        return new PageResult(result.getTotal(), result.getResult());
    }

    @Override
    public PageResult getUserReportByStatus(CheckDTO checkDTO) {
        PageHelper.startPage(checkDTO.getPageIndex(),checkDTO.getPageSize());
        Page<ReportInfo> result = checkMapper.listByStatus(checkDTO.getStatus());

        return new PageResult(result.getTotal() ,result.getResult());
    }

    @Override
    public void passCheck(List<Integer> ids) {
        if(ids.isEmpty()) return ;
        checkMapper.updateStatusByReportId(ids);
    }

    @Override
    public void refuseCheck(List<Integer> ids) {
        if(ids.isEmpty()) return ;
        checkMapper.refuseCheck(ids);
    }
}
